home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Graphics Plus
/
Graphics Plus.iso
/
general
/
viewers
/
polyview
/
hdf-ucd.lha
/
HDF-UCD
/
test2.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-03-04
|
4KB
|
115 lines
#include "brick.h"
#include "test2.h"
main()
{
FILE *f;
int i, j, celltype;
/* read vertices data */
if ((f = fopen(VERTFILE, "r")) == NULL) handleerror(500);
i = 0;
while (fscanf(f, "%f %f %f", &VERTICES[0][i], &VERTICES[1][i],
&VERTICES[2][i]) != EOF) i++;
sizeofvert = i;
fclose(f);
/* read color data
if ((f = fopen(COLORFILE, "r")) == NULL) handleerror(500);
i = 0;
while (fscanf(f, "%f", COLOR+i) != EOF) i++;
sizeofcolor = i;
fclose(f); */
i = 0; if ( (f = fopen(CONNFILE, "r")) == NULL) handleerror(500);
while (fscanf(f, "%d ", &celltype) != EOF) {
switch (celltype) {
case FEhex: if (fscanf(f, "%d %d %d %d %d %d %d %d",
&CONNECTIVITY[i][0],&CONNECTIVITY[i][1],&CONNECTIVITY[i][2],
&CONNECTIVITY[i][3],&CONNECTIVITY[i][4],&CONNECTIVITY[i][5],
&CONNECTIVITY[i][6],&CONNECTIVITY[i][7]) == EOF) handleerror(400);;
CELLID[i] = i; CELLTYPE[i] = FEhex; MATNO[i] = 0; i++;
break;
case FEprism:if ( fscanf(f, "%d %d %d %d %d %d",
&CONNECTIVITY[i][0],&CONNECTIVITY[i][1],&CONNECTIVITY[i][2],
&CONNECTIVITY[i][3],&CONNECTIVITY[i][4],&CONNECTIVITY[i][5]) == EOF)
handleerror(400);;
CONNECTIVITY[i][6] = 0; CONNECTIVITY[i][7] = 0;
CELLID[i] = i; CELLTYPE[i] = FEprism; MATNO[i] = 0; i++;
break;
case FEtet:if ( fscanf(f, "%d %d %d %d ",
&CONNECTIVITY[i][0],&CONNECTIVITY[i][1],&CONNECTIVITY[i][2],
&CONNECTIVITY[i][3]) == EOF) handleerror(400);
CONNECTIVITY[i][4] = 0; CONNECTIVITY[i][5] = 0;
CONNECTIVITY[i][6] = 0; CONNECTIVITY[i][7] = 0;
CELLID[i] = i; CELLTYPE[i] = FEtet; MATNO[i] = 0; i++;
break;
case FEtri: if (fscanf(f, " %d %d %d ",
&CONNECTIVITY[i][0],&CONNECTIVITY[i][1],
&CONNECTIVITY[i][2]) == EOF) handleerror(400);
CONNECTIVITY[i][3]= 0;
CONNECTIVITY[i][4] = 0; CONNECTIVITY[i][5] = 0;
CONNECTIVITY[i][6] = 0; CONNECTIVITY[i][7] = 0;
CELLID[i] = i; CELLTYPE[i] = FEtri; MATNO[i] = 0; i++;
break;
case FEquad: if ( fscanf(f, "%d %d %d %d ",
&CONNECTIVITY[i][0],&CONNECTIVITY[i][1],
&CONNECTIVITY[i][2],&CONNECTIVITY[i][3]) == EOF) handleerror(400);
CONNECTIVITY[i][4] = 0; CONNECTIVITY[i][5] = 0;
CONNECTIVITY[i][6] = 0; CONNECTIVITY[i][7] = 0;
CELLID[i] = i; CELLTYPE[i] = FEquad; MATNO[i] = 0; i++;
break;
default: handleerror(300);
}
}
fclose(f);
sizeofmesh = i;
write_vset ();
}
void write_vset ()
{
int i, gid, ids[MAXREFS];
DF * FEf;
/* Open HDF vset file test1.vset */
FEf = FEopenfile (VSETFILE);
/* ids is an array that stores the reference id of each vdata or vgroup */
i = -1;
ids[++i] = FEstoredata (FEf, "px", VERTICES[0], sizeofvert, LOCAL_FLOATTYPE, 1);
ids[++i] = FEstoredata (FEf, "py", VERTICES[1], sizeofvert, LOCAL_FLOATTYPE, 1);
ids[++i] = FEstoredata (FEf, "pz", VERTICES[2], sizeofvert, LOCAL_FLOATTYPE, 1);
/* you must set the cell sequence if it's not same as the default */
/* bufh is defined in test1.h */
FEsetsequence(FEhex, bufh, 8);
FEsetsequence(FEprism, bufp, 6);
FEsetsequence(FEtet, buft, 4);
/* get connectivities of allfaces and hull only */
ids[++i] = FEhullonly (FEf, CELLTYPE, CONNECTIVITY, "hull", sizeofvert, sizeofmesh);
ids[++i] = FEallfaces (FEf, CELLTYPE, CONNECTIVITY, "plist4", sizeofvert, sizeofmesh);
/* make a new vgroup group1 */
gid = FEmakegroup (FEf, "group1");
/* link all vdata whose reference id is stored in ids to group1(gid) */
FEsetlink (FEf, gid, ids, i+1);
/* close test1.vset */
FEclosefile (FEf);
}